package cn.jji8.patronSaint.quick.config;

import cn.jji8.patronSaint.quick.command.CommandImplement;
import org.bukkit.command.CommandSender;

import java.util.ArrayList;
import java.util.List;

/**
 * 执行对应命令的时候，自动设置ConfigManger对应的值。
 * */
public class DoubleCommandConfig implements CommandImplement {
    static final List<String> list;
    static {
        list = new ArrayList<>();
        list.add("1.5");
        list.add("2.5");
        list.add("5");
        list.add("8");
        list.add("12.2");
    }
    String MessagePromptPrefix;
    ConfigManger configManger;
    String key;
    /**
     * 设置前缀
     * */
    @SuppressWarnings("unused")
    public DoubleCommandConfig setMessagePromptPrefix(String messagePromptPrefix) {
        MessagePromptPrefix = messagePromptPrefix;
        return this;
    }
    private void sendMessage(CommandSender commandSender, String s){
        if(MessagePromptPrefix!=null){
            commandSender.sendMessage(MessagePromptPrefix+s);
        }else {
            commandSender.sendMessage(s);
        }
    }
    public DoubleCommandConfig(ConfigManger configManger, String key) {
        this.configManger = configManger;
        this.key = key;
    }

    /**
     * 当触发此命令的时候，会调用此方法
     */
    @SuppressWarnings("unused")
    @Override
    public void command(CommandSender commandSender, String[] args) {
        if(args.length<1){
            sendMessage(commandSender,"§d请输入设定值");
            return;
        }
        try {
            configManger.set(key,Double.parseDouble(args[0]));
            sendMessage(commandSender,"设置成功，已将"+key+"设为"+args[0]);
        }catch (NumberFormatException e){
            sendMessage(commandSender,"§d"+args[0]+"不是一个整数！");
        }
    }

    /**
     * 当触发补全时，会调用此方法，返回null将会使用Manger.addCommand添加命令时的默认补全列表。
     */
    @SuppressWarnings("unused")
    @Override
    public List<String> TabCompletion(CommandSender commandSender, String[] strings) {
        return list;
    }
}
